//
//  BookManager.m
//  03-BookManageSystem
//
//  Created by mafeng on 16/7/6.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "BookManager.h"

@implementation BookManager
- (instancetype)initWithBookMutabelArray:(NSMutableArray *)array {
    self = [super init];
    if (self) {
        _bookMutableArray = array;
    }
    return self;
}
+ (instancetype)bookManagerWithBookMutableArray:(NSMutableArray *)array {
    return [[[BookManager alloc] initWithBookMutabelArray:array] autorelease];
}
- (void)disPlayBook {
    for (int i = 0; i < self.bookMutableArray.count; i++) {
        NSLog(@"%@", [[self.bookMutableArray objectAtIndex:i] bookName]);
    }
}
- (void)revisePrice:(NSString *)bookName price:(NSNumber *)bookPrice {
    NSInteger index = 0;
    for (int i = 0; i < self.bookMutableArray.count; i++) {
        if ([[[self.bookMutableArray objectAtIndex:i] bookName] isEqualToString:bookName]) {
            index = i;
        }
    }
    [[self.bookMutableArray objectAtIndex:index] setBookPrice:bookPrice];
    NSLog(@"修改后的价格:%@", [[self.bookMutableArray objectAtIndex:index] bookPrice]);
}
- (void)removeBook:(Book *)book {
    [self.bookMutableArray removeObject:book];
}
- (void)addBook:(Book *)book {
    [self.bookMutableArray addObject:book];
}
@end
